﻿using System.Net;

namespace Basic.Repository.Abstract.Models
{
    public class MessageModel<T>
    {

        public HttpStatusCode status { get; set; } = HttpStatusCode.OK;

        public bool success { get; set; } = true;

        public string msg { get; set; } = "";

        public object? msgJson { get; set; }

        public T response { get; set; }


        public static MessageModel<T> Success(string msg = "成功")
        {
            //return Message(true, msg, default);
            return Message(true, msg, default, 200);
        }
        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <returns></returns>
        public static MessageModel<T> Success(T response, string msg = "成功")
        {
            //return Message(true, msg, response);
            return Message(true, msg, response, 200);
        }
        /// <summary>
        /// 返回失败
        /// </summary>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        public static MessageModel<T> Failed(string msg = "失败")
        {
            //return Message(false, msg, default);
            return Message(false, msg, default, 500);
        }
        public static MessageModel Failed(List<string> devMsg, string msg)
        { 
            return Message(devMsg,false, msg, default, 500);
        }

        public static MessageModel<T> Failed(string msg, T response)
        {
            //return Message(false, msg, response);
            return Message(false, msg, response, 500);
        }

        public static MessageModel<T> Message(bool success, string msg, T response)
        {
            return new MessageModel<T>() { msg = msg, response = response, success = success };
        }

        public static MessageModel<T> Message(bool success, string msg, T response, int status)
        {
            return new MessageModel<T>() { msg = msg, response = response, success = success, status = (HttpStatusCode)status };
        }
        public static MessageModel Message(List<string> devMsg,bool success, string msg, T response, int status)
        {
            return new MessageModel() {  devMsg=devMsg, msg = msg, response = response, success = success, status = status };
        }
    }

    public class MessageModel
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public int status { get; set; } = 200;
        /// <summary>
        /// 操作是否成功
        /// </summary>
        public bool success { get; set; } = false;
        /// <summary>
        /// 返回信息
        /// </summary>
        public string msg { get; set; } = "";
        /// <summary>
        /// 返回数据集合
        /// </summary>
        public object response { get; set; }
        public List<string> devMsg { get; set; }
    }
}
